home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Stielhandgranate.lua < prev    next >
Text File  |  2010-08-31  |  7KB  |  177 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Stielhandgranate + Projectile Stielhandgranate
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.stielhandgranate={}
  10. cc.stielhandgranate.stielhandgranate={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.stielhandgranate.gfx_wpn=loadgfx("weapons/stielhandgranate.bmp")                -- Weapon Image
  14. setmidhandle(cc.stielhandgranate.gfx_wpn)
  15. cc.stielhandgranate.sfx_attack=loadsfx("throw.ogg")                                -- Attack Sound
  16. cc.stielhandgranate.sfx_bounce=loadsfx("bounce.wav")                            -- Bounce Sound
  17.  
  18. --------------------------------------------------------------------------------
  19. -- Weapon: Stielhandgranate
  20. --------------------------------------------------------------------------------
  21.  
  22. cc.stielhandgranate.id=addweapon("cc.stielhandgranate","German Stielhandgranate",cc.stielhandgranate.gfx_wpn,1)    -- Add Weapon (1 use)
  23.  
  24. function cc.stielhandgranate.draw()                                                -- Draw
  25.     if weapon_shots<=0 then
  26.         setblend(blend_alpha)
  27.         setalpha(1)
  28.         setcolor(255,255,255)
  29.         drawinhand(cc.stielhandgranate.gfx_wpn,6,0)
  30.     end
  31.     -- HUD chargebar
  32.     if weapon_charge>0 and weapon_shots==0 then
  33.         hudchargebar(weapon_charge,100)
  34.     end
  35.     -- HUD Crosshair / HUD Timer
  36.     if weapon_shots==0 then
  37.         hudcrosshair(4,3)
  38.         hudtimer(3,1,10)
  39.     end
  40. end
  41.  
  42. function cc.stielhandgranate.attack(attack)                                        -- Attack
  43.     if (weapon_shots<=0) then
  44.         -- Charge
  45.         if (attack==1) then
  46.             -- No more weapon switching!
  47.             useweapon(0)
  48.             weapon_charge=weapon_charge+1                                        -- Increase charge
  49.         end
  50.         -- Fire a projectile (on release/full charge)
  51.         if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
  52.             playsound(cc.stielhandgranate.sfx_attack)
  53.             weapon_shots=weapon_shots+1
  54.             id=createprojectile(cc.stielhandgranate.stielhandgranate.id)
  55.             projectiles[id]={}
  56.             -- Ignore collision with current player at beginning
  57.             projectiles[id].ignore=playercurrent()
  58.             -- Set initial position of projectile
  59.             projectiles[id].x=getplayerx(0)+(4*getplayerdirection(0))
  60.             projectiles[id].y=getplayery(0)+3
  61.             -- Initial collision check (avoid throwing into other objects)
  62.             for i=0,10,1 do
  63.                 if collision(col5x5,projectiles[id].x+math.sin(math.rad(getplayerrotation(0)))*i,projectiles[id].y-math.cos(math.rad(getplayerrotation(0)))*i)==1 then
  64.                     if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  65.                         if (i==0) then
  66.                             projectiles[id].x=getplayerx(0)
  67.                             projectiles[id].y=getplayery(0)+3
  68.                             break
  69.                         else
  70.                             projectiles[id].x=getplayerx(0)+(4*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*(i-1)
  71.                             projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*(i-1)
  72.                             break
  73.                         end
  74.                     end
  75.                 end
  76.             end
  77.             -- Set speed of projectile
  78.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  79.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  80.             -- Rot
  81.             projectiles[id].rot=getplayerrotation(0)
  82.             -- Set timer
  83.             projectiles[id].timer=weapon_timer*50
  84.             -- Effects
  85.             recoil(2)
  86.             -- End Turn
  87.             endturn()
  88.         end
  89.     end
  90. end
  91.  
  92. --------------------------------------------------------------------------------
  93. -- Projectile: Stielhandgranate
  94. --------------------------------------------------------------------------------
  95.  
  96. cc.stielhandgranate.stielhandgranate.id=addprojectile("cc.stielhandgranate.stielhandgranate")    -- Add Projectile
  97.  
  98. function cc.stielhandgranate.stielhandgranate.draw(id)                            -- Draw
  99.     -- Setup draw mode
  100.     setblend(blend_alpha)
  101.     setalpha(1)
  102.     setcolor(255,255,255)
  103.     setscale(1,1)
  104.     -- Calculate projectile rotation
  105.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))+projectiles[id].rot)
  106.     -- Draw projectile
  107.     drawimage(cc.stielhandgranate.gfx_wpn,projectiles[id].x,projectiles[id].y)
  108.     -- Draw Arrow if out of Screen
  109.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  110. end
  111.  
  112. function cc.stielhandgranate.stielhandgranate.update(id)                        -- Update
  113.     -- Rotate
  114.     projectiles[id].rot=projectiles[id].rot+projectiles[id].sx+projectiles[id].sy
  115.     -- Gravity influence on speed
  116.     projectiles[id].sy=projectiles[id].sy+getgravity()
  117.     -- Move (in substep loop for optimal collision precision)
  118.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  119.     msubx=projectiles[id].sx/msubt
  120.     msuby=projectiles[id].sy/msubt
  121.     for i=1,msubt,1 do
  122.         -- Move X
  123.         projectiles[id].x=projectiles[id].x+msubx
  124.         if collision(col5x5,projectiles[id].x,projectiles[id].y)==1 then
  125.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  126.                 if (math.abs(projectiles[id].sx)>0.5) then playsound(cc.stielhandgranate.sfx_bounce) end
  127.                 projectiles[id].x=projectiles[id].x-msubx
  128.                 projectiles[id].sx=-projectiles[id].sx*0.3
  129.                 msubx=-msubx*0.3
  130.             end
  131.         else
  132.             projectiles[id].ignore=0
  133.         end
  134.         -- Move Y
  135.         projectiles[id].y=projectiles[id].y+msuby
  136.         if collision(col5x5,projectiles[id].x,projectiles[id].y)==1 then
  137.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  138.                 if (math.abs(projectiles[id].sy)>0.5) then playsound(cc.stielhandgranate.sfx_bounce) end
  139.                 projectiles[id].y=projectiles[id].y-msuby
  140.                 projectiles[id].sy=-projectiles[id].sy*0.3
  141.                 msuby=-msuby*0.3
  142.                 projectiles[id].sx=projectiles[id].sx*0.9
  143.                 msubx=msubx*0.9
  144.             end
  145.         else
  146.             projectiles[id].ignore=0
  147.         end        
  148.         -- Water
  149.         if (projectiles[id].y)>getwatery()+5 then
  150.             -- Effects
  151.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  152.             playsound(sfx_hitwater1)
  153.             -- Free projectile
  154.             freeprojectile(id)
  155.             break
  156.         end
  157.     end
  158.     -- Timer -> Explode
  159.     projectiles[id].timer=projectiles[id].timer-1
  160.     if projectiles[id].timer<=0 then
  161.         -- Cause damage
  162.         arealdamage(projectiles[id].x,projectiles[id].y,120,55)
  163.         -- Destroy terrain
  164.         terrainexplosion(projectiles[id].x,projectiles[id].y,35,1)
  165.         -- Crater
  166.         grey=math.random(0,40)
  167.         if math.random(0,1)==1 then
  168.             terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  169.         else
  170.             terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  171.         end
  172.         -- Free projectile
  173.         freeprojectile(id)
  174.     end
  175.     -- Scroll to projectile
  176.     scroll(projectiles[id].x,projectiles[id].y)
  177. end